<h2>Редактировать страницу</h2><br/>
<div class="tabulation" data-id="tabs-1">
	<a class="element active" data-id="tab-1">Основное</a>
	<? $tab_num = 2; ?>
	<? foreach( $this->langs as $l => $lang ): ?>
		<a class="element" data-id="tab-<?=$tab_num++?>"><?=Yii::t('lang',$lang)?></a>
	<? endforeach; ?>
</div>
<div class="scrollable">
	<form action="<?= CHtml::normalizeUrl(array('page/savePage', 'id'=> isset($item)?$item->id:'new'))?>" method="POST">
	<div class="tabs" id="tabs-1">
		<div class="tab active" id="tab-1">
			<table>
					<tbody>
					<tr>
						<td>Порядок:</td>
						<td><input type="text" class="input" name="item[order]" value="<?= isset($item)?$item->order:'0'?>" required id="order"></td>
					</tr>
					<tr>
						<td>URL в адресной строке:</td>
						<td><input type="text" class="input" name="item[url]" value="<?= isset($item)?$item->url:'' ?>" id="url"></td>
					</tr>
					</tbody>
				</table>
		</div>
		<? $tab_num =2; ?>
		<? foreach( $this->langs as $l => $lang ):
			if( $l === Yii::app()->params['defaultLanguage'] ) {
				$suffix = '';
			} else {
				$suffix = '_'.$l;
			}
			?>
			<div class="tab" id="tab-<?=$tab_num++?>">
				<table class="step-right">
					<tr>
						<td><strong>Название:</strong></td>
						<td><input class="input wide" name="item[title<?=$suffix?>]" type="text" id="name" value="<?=isset($item)?($suffix=='')?$item->title:$item->getLangAttribute('title_' . $l):''?>"></td>
					</tr>
					<tr>
						<td>Контент:</td>
						<td></td>
					</tr>
					<tr>
						<td colspan="3">
							<textarea name="item[body<?=$suffix?>]" class="input wide"><?=isset($item)?($suffix=='')?$item->body:$item->getLangAttribute('body_' . $l):''?></textarea>
						</td>
					</tr>
				</table>
			</div>
		<?php endforeach; ?>
		<input type="submit" class="btn-green save-btn" value="Сохранить"/>
	</div>
	</form>
</div>
<script type="text/javascript">
	$(function(){
		<? foreach( $this->langs as $l => $lang ):
		if( $l === Yii::app()->params['defaultLanguage'] ) {
			$suffix = '';
		} else {
			$suffix = '_'.$l;
		}
		?>
		var editor<?=$suffix?>;
		editor<?=$suffix?> = CKEDITOR.replace( 'item[body<?=$suffix?>]',
			{
				filebrowserBrowseUrl :'/instinct/js/ckeditor/filemanager/browser/default/browser.html?Connector=/instinct/js/ckeditor/filemanager/connectors/php/connector.php',
				filebrowserImageBrowseUrl : '/instinct/js/ckeditor/filemanager/browser/default/browser.html?Type=Image&Connector=/instinct/js/ckeditor/filemanager/connectors/php/connector.php',
				filebrowserFlashBrowseUrl :'/instinct/js/ckeditor/filemanager/browser/default/browser.html?Type=Flash&Connector=/instinct/js/ckeditor/filemanager/connectors/php/connector.php',
				filebrowserUploadUrl  :'/instinct/js/ckeditor/filemanager/connectors/php/upload.php?Type=File',
				filebrowserImageUploadUrl : '/instinct/js/ckeditor/filemanager/connectors/php/upload.php?Type=Image',
				filebrowserFlashUploadUrl : '/instinct/js/ckeditor/filemanager/connectors/php/upload.php?Type=Flash',
				width: '90%'
			});

		<? endforeach; ?>
		$('.popup-outer').click(function() {
			for(name in CKEDITOR.instances)
			{
				CKEDITOR.instances[name].destroy()
			}

		});
		$('.tabulation .element').click(function() {
			$('.tabulation .element').removeClass('active');
			$(this).addClass('active');
			$('#' + $(this).parent().data('id') + ' > .tab').hide();
			$('#' + $(this).data('id')).show();

		});
		$('.autofill').keyup(function( ) {
			var count = 0;
			var current_value = $(this).val();
			$('#av-' + $(this).attr('id')).children().each(function() {
				if ($(this).html().toLowerCase().indexOf(current_value.toLowerCase()) != -1) {
					$(this).show();
					count++;
				} else {
					$(this).hide();
				}
			});
			if (count > 0) {
				$('#av-' + $(this).attr('id')).show();
			};
		});
		$(".autofill-values > .element").click(function() {
			$("#" + $(this).data('id')).val($(this).html());
			$(this).parent().hide();
		});
		$('html').click(function() {
			$('.autofill-values').hide();
			console.log('ok');
		});
		$('.autofill-holder').click(function(e) {
			e.stopPropagation();
		});
	});
</script>
